<?php $this->pageHeader('Medlemmer'); ?>

<?php echo $this->flashMessage()->renderMessages(); ?>

<div class="header_wrapper">
    <h1>Medlemmer</h1>
    <?php echo $this->filterForm; ?>
</div>

<table class="admin_member">
    <thead>
        <tr>
            <th>Navn</th>
            <th>Telefon</th>
            <th>Epost</th>
            <th>Medlemsnr</th>
            <th>Brukerprofil</th>
        </tr>
    </thead>
    <tbody>
<?php
    foreach($this->members as $member) {
        $name = $this->escape($member->first_name) . ' ' . $this->escape($member->last_name);
        $phone = is_null($member->Phonenumbers) || count($member->Phonenumbers) == 0 ? '' : $member->Phonenumbers[0]->number;

        $email = null;

        if(count($member->emails) > 0) {
            foreach($member->emails as $e) {
                if($e->is_main) {
                    $email = $e->address;
                    break;
                }
            }
            $email = is_null($email) ? $member->emails[0]->address : $email;
        }
        $username = is_null($member->User) ? '' : '<a href="' . $this->url(array('module' => 'core', 'controller' => 'user', 'action' => 'view', 'id' => $member->User->id), null, true) . '">' . $member->User->username . '</a>';
?>
    <tr>
        <td><a href="<?php echo $this->url(array('module' => 'admin', 'controller' => 'member', 'action' => 'edit', 'id' => $member->id), null, true); ?>"><?php echo $name; ?></a></td>
        <td><?php echo $phone; ?></td>
        <td><?php echo $email; ?></td>
        <td><?php echo ((int)$member->redcross_id != 0 ? $member->redcross_id : ""); ?></td>
        <td><?php echo $username; ?></td>
    </tr>
<?php
        // Have to reset this variable
        $email = null;
    }
?>
    </tbody>
</table>
<?php echo $this->paginationLinks; ?>
